package extrator.popup.actions;

import extrator.views.XPEWSView;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

public class ListarOperationsAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate,
												IEditorActionDelegate{

	private String xpews;
	private IWorkbenchWindow window;
	public static final String ID = "extrator.views.XPEWSView";
	
	@Override
	public void run(IAction action) {
		window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		IWorkbenchPage page = window.getActivePage();
		try {
			page.showView(ID);
			XPEWSView view = (XPEWSView) page.findView(ID);
			view.setArquivoXpews(xpews);
			view.getAction1().run();
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		xpews = selection.toString();
	}
	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
	}
	@Override
	public void dispose() {
	}
	@Override
	public void init(IWorkbenchWindow window) {
		this.window = window;
	}
	@Override
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
		/*IEditorInput input = targetEditor.getEditorInput();
		System.out.printf("\nHA\n%s\n", input);*/
	}
}
